package com.jl.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @version 2012.10.27
 * @author LuHongjun
 */
public class StrUtil {

	private final static Pattern p = Pattern.compile("\\s+");

	private final static String SPACE = " ";

	public static String replaceSpace(String data) {
		if (data == null)
			return "";
		Matcher m = p.matcher(data);
		String temp = m.replaceAll("");
		return temp;
	}

	public static String trimStrToZero(String data) {
		if (data == null) {
			return "0";
		} else if (data.trim().equals("")) {
			return "0";
		} else {
			return data.trim();
		}
	}

	public static String trimBeginZero(String data) {
		String temp = data.trim();
		int i = 0;
		for (; i < temp.length(); i++) {
			if (data.charAt(i) == '0') {
				continue;
			} else {
				break;
			}
		}
		return temp.substring(i);
	}

	public static String strHexArrayToStrHexFormat(String[] array) {
		StringBuilder sb = new StringBuilder();
		if (array == null || array.length == 0) {
			return "No Data";
		}
		for (String str : array) {
			sb.append(str);
		}
		return HexUtil.format(sb.toString());
	}
}
